home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / Sample4 / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  3.8 KB  |  135 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef FRAME_H
  6. #include "Frame.h"
  7. #endif
  8.  
  9. #ifndef PART_H
  10. #include "Part.h"
  11. #endif
  12.  
  13. // ----- Framework Layer -----
  14. #ifndef FWCONTXT_H
  15. #include "FWContxt.h"            // FW_CViewContext
  16. #endif
  17.  
  18. // ----- OS Layer -----
  19. #ifndef FWCFMRES_H
  20. #include "FWCFMRes.h"            // FW_PSharedLibraryResourceFile
  21. #endif
  22.  
  23. // ----- Graphic Includes -----
  24. #ifndef FWRECT_H
  25. #include <FWRect.h>                // FW_CRect
  26. #endif
  27.  
  28. #ifndef FWRECSHP_H
  29. #include "FWRecShp.h"            // FW_CRectShape
  30. #endif
  31.  
  32. #ifndef FWPICSHP_H
  33. #include "FWPicShp.h"            // FW_CPicture, FW_CPictureShape
  34. #endif
  35.  
  36. #ifndef FWRRCSHP_H
  37. #include "FWRRcShp.h"            // FW_CRoundRectShape
  38. #endif
  39.  
  40. #ifndef SOM_DevUniv_STalker_xh
  41. #include "STalker.xh"            // for STalker
  42. #endif 
  43.  
  44. //========================================================================================
  45. #ifdef FW_BUILD_MAC
  46. #pragma segment Sample4
  47. #endif
  48.  
  49. //========================================================================================
  50. FW_DEFINE_AUTO(CSample4Frame)
  51.  
  52. const FW_Boolean kWaitUntilDone = TRUE;    // don't return until talking is finished.
  53. //========================================================================================
  54. CSample4Frame::CSample4Frame(Environment* ev, ODFrame* odFrame, 
  55.                                     FW_CPresentation* presentation, CSample4Part* sample3Part)
  56.   : FW_CFrame(ev, odFrame, presentation, sample3Part),
  57.       fSOMTalker(NULL),
  58.       fPictShape(NULL)
  59. {
  60.     this->MyInitPicture(ev);
  61. #ifdef FW_BUILD_MAC                    // can we do text-to-speech on Windows?
  62.     fSOMTalker = new DevUniv_STalker;    
  63.     fSOMTalker->SayString(ev, "I use ODF", !kWaitUntilDone);    // say it!
  64. #endif
  65.     FW_END_CONSTRUCTOR
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. void
  70. CSample4Frame::MyInitPicture(Environment* ev)
  71. {
  72.     FW_PSharedLibraryResourceFile resFile(ev);        // PICT resource in shared library
  73. #ifdef FW_BUILD_MAC
  74.     const short kPictID = 2000;
  75.     FW_CPicture picture(resFile, kPictID);
  76.     fFrameRect = this->GetBounds(ev);                // Get new Frame Rect
  77.     fPictShape = FW_NEW(FW_CPictureShape, (picture, fFrameRect));
  78. #endif
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. CSample4Frame::~CSample4Frame()
  83. {
  84.     FW_START_DESTRUCTOR
  85.     delete fPictShape;
  86. #ifdef FW_BUILD_MAC
  87.     delete fSOMTalker;
  88. #endif
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. void 
  93. CSample4Frame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  94. {
  95.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  96.     // erase invalid shape
  97.     FW_CRect invalidRect;
  98.     context.GetClipRect(invalidRect);
  99.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  100.  
  101.     // draw the picture
  102.     fPictShape->Render(context);
  103.  
  104.     // draw a frame around it
  105.     FW_CRoundRectShape::RenderRoundRect(context,
  106.                                         fFrameRect, 
  107.                                         FW_CPoint(FW_IntToFixed(30), FW_IntToFixed(30)),
  108.                                         FW_kFrame,
  109.                                         FW_CInk(FW_kRGBBlue));
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. FW_Handled 
  114. CSample4Frame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  115. {    
  116.     FW_UNUSED(theMouseEvent);
  117. #ifdef FW_BUILD_MAC
  118.     fSOMTalker->SayString(ev, "Oh Boy", !kWaitUntilDone);    // say it!
  119. #endif
  120.     return true;    // we handled event
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. void 
  125. CSample4Frame::FrameShapeChanged(Environment* ev)
  126. {
  127.     FW_CFrame::FrameShapeChanged(ev);
  128.     fFrameRect = this->GetBounds(ev);        // Get new frame rect
  129.     // modify picture
  130.     FW_CPicture picture = fPictShape->GetPicture();
  131.     fPictShape->SetGeometry(picture, fFrameRect);
  132.     // force redraw of whole frame
  133.     this->Invalidate(ev, fFrameRect);            
  134. }
  135.